package com.zhihuiyanche.controller.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class LoginController
{

	/**
	 * 跳转到登陆页
	 *
	 * @param req
	 * @param resp
	 * @param context
	 * @return
	 */
	@RequestMapping(value = "toLogin", method =	{ RequestMethod.POST, RequestMethod.GET })
	public ModelAndView toLoginPage(HttpServletRequest req, HttpServletResponse resp, ModelMap context)
	{
		ModelAndView mv = new ModelAndView("sign-in");
		return mv;
	}

	/**
	 * 跳转到注册页
	 *
	 * @param req
	 * @param resp
	 * @param context
	 * @return
	 */
	@RequestMapping(value = "signUp", method ={ RequestMethod.POST, RequestMethod.GET })
	public ModelAndView signUp(HttpServletRequest req, HttpServletResponse resp, ModelMap context)
	{
		ModelAndView mv = new ModelAndView("sign-up");
		return mv;
	}
	
	/**
	 * 注销并跳转到登陆页
	 *
	 * @param req
	 * @param resp
	 * @param context
	 * @return
	 */
	@RequestMapping(value = "logout", method =	{ RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody String logout(HttpServletRequest req, HttpServletResponse resp,HttpSession session, ModelMap context)
	{
		session.invalidate();
		return "1";
	}

}